from exts import db



# 菜单表
class Menu(db.Model):
    """菜单表"""
    __tablename__ = "t_menu"
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'comment': '菜单表'
    }

    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='菜单id')
    menu_name = db.Column(db.String(32), comment='菜单名称')
    menu_link = db.Column(db.String(255), comment='url请求地址')
    menu_order = db.Column(db.Integer, comment='菜单顺序')
    menu_parent_id = db.Column(db.Integer, comment='父菜单id')  # 如果此项为 null，那么它就是顶级菜单
    menu_permission_list = db.Column(db.String(32),comment='权限标识列表')  # 【1,2,3】  parent_id 加权限列表来给出菜单



# 权限表
class Permission(db.Model):
    """权限表"""
    __tablename__ = "t_permission"
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'comment': '权限表'
    }

    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='权限id')
    permission_name = db.Column(db.String(32), comment='权限名称')
    permission_code = db.Column(db.String(32), comment='权限代码')


# 用户权限关联表
class UserPermission(db.Model):
    """用户权限关联表"""
    __tablename__ = "t_user_permission"
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'comment': '用户权限关联表'
    }

    id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='关联表id')
    user_id = db.Column(db.Integer,comment='用户id')
    permission_id = db.Column(db.Integer,comment='权限id')


# 用户表
class User(db.Model):
    """用户表"""
    __tablename__ = "t_user"
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'comment': '用户表'
    }

    id = db.Column(db.Integer, primary_key=True,autoincrement=True,comment='用户id')  # 整型的主键，会默认设置为自增主键
    username = db.Column(db.String(32),comment='用户名称')
    password = db.Column(db.Text,comment='用户密码')
    email = db.Column(db.String(32),comment='用户邮箱')
    user_status = db.Column(db.String(32),server_default='1',comment='账号状态 1.启用 0.禁用')
    create_time = db.Column(db.DateTime, server_default=db.func.now(),comment='创建时间')
    end_login_time = db.Column(db.DateTime,comment='最后登录时间')


# 模型类型表
class Model_Type(db.Model):
    """模型类型表"""
    __tablename__ = "t_model_type"
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'comment': '模型类型表'
    }

    id = db.Column(db.Integer, primary_key=True,autoincrement=True,comment='类型id')  # 整型的主键，会默认设置为自增主键
    model_type_name = db.Column(db.String(32),comment='类型名称')
    model_type_title = db.Column(db.Text,comment='类型详情')
    create_time = db.Column(db.DateTime, server_default=db.func.now(),comment='创建时间')



# 模型表
class Model(db.Model):
    """模型表"""
    __tablename__ = "t_model"
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'comment': '模型表'
    }

    id = db.Column(db.Integer, primary_key=True,autoincrement=True,comment='模型id')  # 整型的主键，会默认设置为自增主键
    user_id = db.Column(db.Integer,comment='用户id')
    model_name = db.Column(db.String(32),comment='模型名称')
    model_title = db.Column(db.Text,comment='模型详情')
    create_time = db.Column(db.DateTime, server_default=db.func.now(),comment='创建时间')
    t_model_type_id = db.Column(db.Integer,comment='模型分类id')


# 数据集文件表
class Folder(db.Model):
    """数据集文件表"""
    __tablename__ = "t_folder"
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'comment': '数据集文件表'
    }

    id = db.Column(db.Integer, primary_key=True,autoincrement=True,comment='文件夹id')  # 整型的主键，会默认设置为自增主键
    folder_name = db.Column(db.String(32),comment='文件夹名称')
    folder_parent_id = db.Column(db.Integer, comment='文件夹父类id')
    folder_list = db.Column(db.Text,comment='文件夹列表')
    create_time = db.Column(db.DateTime, server_default=db.func.now(),comment='创建时间')


# 数据集文件版本表
class Folder_Version(db.Model):
    """数据集文件版本表"""
    __tablename__ = "t_folder_version"
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'comment': '数据集文件版本表'
    }

    id = db.Column(db.Integer, primary_key=True,autoincrement=True,comment='文件夹id')  # 整型的主键，会默认设置为自增主键
    flag = db.Column(db.Boolean,server_default='0',comment='最新版本标识')
    version = db.Column(db.String(32),comment='版本号')
    training_set = db.Column(db.String(32),comment='训练集比例')
    test_set = db.Column(db.String(32),comment='测试集比例')
    create_time = db.Column(db.DateTime, server_default=db.func.now(),comment='创建时间')
    t_folder_id = db.Column(db.Integer, comment='数据集文件id')


# 训练配置表
class Model_Config(db.Model):
    """训练配置表"""
    __tablename__ = "t_model_config"
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'comment': '训练配置表'
    }

    id = db.Column(db.Integer, primary_key=True,autoincrement=True,comment='训练配置id')  # 整型的主键，会默认设置为自增主键
    iteration_num = db.Column(db.Integer,comment='训练迭代次数')
    study_percentum= db.Column(db.Integer, comment='学习率')
    process_num = db.Column(db.Integer, comment='训练集加载进程数')
    create_time = db.Column(db.DateTime, server_default=db.func.now(), comment='创建时间')
    user_id = db.Column(db.Integer, comment='用户id')
    t_folder_id = db.Column(db.Integer, comment='数据集文件id')



# 训练结果表
class Model_Result(db.Model):
    """训练结果表"""
    __tablename__ = "t_model_result"
    __table_args__ = {
        'mysql_engine': 'InnoDB',
        'comment': '训练结果表'
    }

    id = db.Column(db.Integer, primary_key=True,autoincrement=True,comment='训练结果id')  # 整型的主键，会默认设置为自增主键
    state = db.Column(db.Integer,comment='训练状态')
    create_time = db.Column(db.DateTime, server_default=db.func.now(),comment='创建时间')
    t_model_id = db.Column(db.Integer, comment='模型id')
    folder_version_id = db.Column(db.Integer, comment='文件版本id')

